package com.example.yuejian.yuejian.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.adapter.ClubCoachIntroAdapter;
import com.example.yuejian.yuejian.base.BaseFragment;
import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.ClubInfo;
import com.example.yuejian.yuejian.bean.Masters;
import com.example.yuejian.yuejian.model.ClubModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubIntroFragment extends BaseFragment {
    private  View view;
    private RecyclerView recyclerView;
    private TextView intro_content;
    private  TextView club_address;
    private  TextView club_phone;
    private TextView club_time;

    private ModleListener<ClubInfo>clubInfoModleListener=new ModleListener<ClubInfo>() {
        @Override
        public void onResponse(ClubInfo o) {
            ClubInfo res=o;
            intro_content.setText(res.getIntro());
            club_address.setText(res.getAddress());
            club_phone.setText(res.getPhone());
            club_time.setText(res.getTime());
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getActivity(),"cuowu",Toast.LENGTH_SHORT).show();
        }
    };

    List<Masters> list;
    private ModleListListener<Masters>mastersModleListListener=new ModleListListener<Masters>() {
        @Override
        public void onResponse(List<Masters> l) {
            list=l;
            recyclerView.setAdapter(new ClubCoachIntroAdapter(getActivity(),list));
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getActivity(),"cuowu",Toast.LENGTH_SHORT).show();
        }
    };

    public ClubIntroFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_club_intro, container, false);
        initViews();
        getDate();
        return view;
    }
    private void initViews()
    {
        recyclerView=(RecyclerView)view.findViewById(R.id.club_intro_coachIntro_recycleview);
        // GridLayoutManager gm = new GridLayoutManager(this.getActivity(),2);
        // 网格是的list布局   2列
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        //recyclerView.setLayoutManager(gm);

        intro_content=(TextView)view.findViewById(R.id.club_detail_intro_content);
        club_address=(TextView)view.findViewById(R.id.club_detail_address);
        club_phone=(TextView)view.findViewById(R.id.club_detail_phone);
        club_time=(TextView)view.findViewById(R.id.club_detail_time);
    }
 private void getDate()
 {

     ClubModel model=new ClubModel();
     model.ClubDetail(get_Cid(),clubInfoModleListener);
      model.CoachList(get_Cid(),mastersModleListListener);
 }
}
